﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DA
{
    public class PhieuGiaHanDA:DBConnection
    {
        public PhieuGiaHanDA()
        {
            sqlCommand.Connection = sqlConnection;
        }
        public int Add(DTO.PhieuGiaHanDTO item)
        {
            var query = String.Format("insert into PHIEUGIAHAN values('{0}','{1}','{2}'); select SCOPE_IDENTITY();",
                            item.MaPhieuDangKy,
                            item.NgayGiaHan,
                            item.TongTienGiaHan);
            sqlCommand.CommandText = query;
            try
            {
                open();
                var idRe = -1;
                sqlCommand.CommandText = query;
                var re = sqlCommand.ExecuteScalar().ToString();
                idRe = Int32.Parse(re);
                close();
                return idRe;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return -1;
            }
        }
        public string getNgayGiaHan(string _Maphieudangky)
        {
            string ngaygiahan = String.Format("select NgayGiaHan from PHIEUGIAHAN where MaPhieuDangKy='{0}'", _Maphieudangky);
            return new  MyQueryDA().getValues(ngaygiahan);
        }
        public int getMaPhieuGiaHan(string _Maphieudangky)
        {
            string query = String.Format("select MaPhieuGiaHan from PHIEUGIAHAN where MaPhieuDangKY='{0}'", _Maphieudangky);
            return new MyQueryDA().getId(query);
        }
    }
}
